package com.jr.dao.impl;

import com.jr.dao.EnterpriseDao;
import com.jr.pojo.Enterprise;
import com.jr.util.DBHelper;

import java.util.ArrayList;

public class IEnterpriseDaoImpl implements EnterpriseDao {
    DBHelper db = new DBHelper();
    @Override
    public int insertEnterprise(Enterprise enter) {
        /*插入企业信息*/
       /* String sql = "insert into enterprise values(null,?,?,?,?,?,?,?)";
        return  db.dtUpdate(sql,enter.getName(),enter.getUniformcode(),enter.getEmail(),enter.getPhone(),enter.getAddress(),enter.getScale(),enter.getFax());*/
        String sql = "INSERT INTO enterprise (entername, uniformcode, email, phone, address, scale, fax) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?)";
        Object objs[] = {enter.getEntername(), enter.getUniformcode(), enter.getEmail(), enter.getEmail(),
                enter.getAddress(), enter.getScale(), enter.getFax()};
        return db.dtUpdate(sql, objs);
    }


    @Override
    public ArrayList<Enterprise> selectEnterprise(Enterprise enter) {
        String sql = "select * from enterprise where entername=?";
        ArrayList<Enterprise> list  =db.dtQuery(sql,enter.getClass(),enter.getEntername());
        return list;
    }

    @Override
    /*回显数据 根据企业名字 确定一个对象 拿出对象下的其他值*/
    public Enterprise selectEnterByName(String edirname) {
        String sql = "select * from enterprise where entername=?";
        ArrayList<Enterprise> list  =db.dtQuery(sql,Enterprise.class,edirname);
        if (list == null || list.isEmpty()) {
            return null; // 或者 throw new RuntimeException("未找到企业信息");
        }
        return list.get(0);
    }

  /*  @Override
    public ArrayList<Enterprise> selectEnterByName(Enterprise enter) {
        return null;
    }*/
}
